/**
 * 用户模块路由文件
 */

const Router = require('koa-router');
const router = new Router();
const { validate } = require('../validators/common');
const { add, update, search, deleteUser, updatePassword, changeStatus, login } = require('../services/users');
const { validAdd, validUpdate, validSearch, validUpdatePassword, validChangeStatus, validLogin } = require('../validators/users');
const { authorization } = require('./common');

router.prefix('/users');

router.post('/add', authorization('usersAdd'), validate(validAdd), add);

router.put('/update', authorization('usersUpdate'), validate(validUpdate), update);

router.get('/search', authorization('usersSearch'), validate(validSearch), search);

router.delete('/delete/:id', authorization('usersDelete'), deleteUser);

router.put('/updatePassword', authorization('usersUpdatePassword'), validate(validUpdatePassword), updatePassword);

router.put('/changeStatus', authorization('usersChangeStatus'), validate(validChangeStatus), changeStatus);

router.post('/login', validate(validLogin), login);

module.exports = router;